﻿<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%@page import="com.aiflow.Action.DictionaryAction;"%>
<html>
<head>
<%
String handleIds = request.getParameter("handleIds");
%>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript">
	var alarmTypes = [];
	var editHandleFormPanel = null;
	var sexStore ;
	var checkid ='-1' ;
  	var  checktext = '' ;
		$(document).ready(function(){
			// 工具栏
		    var toolbar = new Ext.Toolbar({
		    	renderTo: 'editHandleToolBarDiv',
		    	items: [
				    new Ext.Button({
					    id: 'editHandle-save-button',
						text: '保存',
						iconCls: 'tick'
					}),
					new Ext.Button({
					    id: 'editHandle-cancel-button',
						text: '取消',
						iconCls: 'cancel'
					})
				]
			});
               
            // 工单类型数据源
	        var alarmStore = new Ext.data.ArrayStore({  
	            fields : ['supervise_id', 'supervise_name'],  
	            data : <%=DictionaryAction.getDictionaryCombo("741")%>,
	            sortInfo: {field: "supervise_id", direction: "ASC"}
	        });
	        
		   //  告警对象 树      
		   var comboWithTooltipHandle = new Ext.form.ComboBox({
		    id:'ch',
		    fieldLabel: '督办对象',
            store:new Ext.data.SimpleStore({fields:[],data:[[]]}),  
            editable:false,  
             hiddenName:'target_name',
           //  hiddenId:'dicId',
             hiddenId:'alarmTargetId',
            mode: 'local',  
            triggerAction:'all',  
            maxHeight: 200, 
			allowBlank:false, 
            tpl: '<div style="height:200px"><div id="treeHandle"></div></div>',  
            onSelect:Ext.emptyFn,
            emptyText:'请选择...',
            anchor:'98%',
            applyTo: 'comboxtreeHandle'  
        });
       
        comboWithTooltipHandle.render('comboWithTooltipHandle');  
        
        var treeHandle = new Ext.tree.TreePanel({  
                border:false,  
                autoScroll:true,
                animate:true,
                autoWidth:true,
                autoHeight:true,
                enableDD:true,
                containerScroll: true, 
                loader: new Ext.tree.TreeLoader({
                    dataUrl:'${pageContext.request.contextPath}/dictionary_getDictionaryTreehadle.action?alarmId='+<%=handleIds%>,
                    listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.parentId = node.id
						this.baseParams.text = node.text
						this.baseParams.leaf = node.leaf
					}
				}           
                })
            });
            
        var rootHerald = new Ext.tree.AsyncTreeNode({
                id:'748',                      //节点id
                text: '督办对象',                  //节点名称
                draggable:true,                  //是否支持拖动
                nodeType: 'async', 
                leaf:false,
                checked : false
        });
          
            treeHandle.setRootNode(rootHerald);
            comboWithTooltipHandle.on('expand',function(){  
            treeHandle.render('treeHandle');  
            //加载所有的子节点
            //tree.expandAll(); 
               // rootHerald.eachChild(
            });  
            
        treeHandle.on('checkchange', function(node, checked) {
                        node.expand();
                        node.attributes.checked = checked;
                        node.eachChild(function(child) {
                                    child.ui.toggleCheck(checked);
                                    child.attributes.checked = checked;
                                    child.fireEvent('checkchange', child,
                                            checked);
                               });
                            //这里是遍历勾选的角色
                            var b = treeHandle.getChecked();
                            checkid = new Array;// 存放选中id的数组
                            checktext = new Array;// 存放选中text的数组
                            for (var i = 0; i < b.length; i++) {
                                checktext.push(b[i].text);// 添加text到数组
                                checkid.push(b[i].id);// 添加id到数组
                                
                            }
                       comboWithTooltipHandle.setValue(checktext.toString());
                    }, treeHandle);
          
		 	// 编辑用户Form
			var editHandleFormPanel = new Ext.FormPanel({
				renderTo: 'editHandleFormDiv',
		        labelWidth: 60,
		        border: false,
		        bodyStyle: 'background-color:transparent;',
		          items: [{
		            layout:'form',
		            border: false,
		            bodyStyle: 'padding:5px;background-color:transparent;',
		            items:[{//  传报编号
			                xtype:'hidden',
			                id: 'id',
			                name: 'id',
			                fieldLabel: '督办编号',
			                readOnly: true,
			                anchor:'98%',
			                allowBlank:false,
			                maxLength: 20
		                   },{//  传报编号
			                xtype:'hidden',
			                id: 'targetName',
			                name: 'targetName',
			                fieldLabel: '督办对象',
			                readOnly: true,
			                anchor:'98%',
			                allowBlank:false,
			                width: 230,
			                maxLength: 20
		                   },{  
			                xtype:'combo',
			                hiddenName: 'supervise_id',
			                fieldLabel: '工单类型',
			                store: alarmStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'supervise_id',
			                displayField: 'supervise_name',
			                allowBlank:false,
			                editable: false,
							allowBlank:false,
			                width: 230,
			                anchor:'98%'
			           },comboWithTooltipHandle,   // 传报对象
		                { 
		xtype:'timefield',  
		columnWidth:.5 ,            
                maxValue:'23:30',                      //最大时间   
                maxText:'所选时间小于{0}',  
                minValue:'00:00',                      //最小时间   
                minText:'所选时间大于{0}',  
                maxHeight:70,  
                increment:30,   
				allowBlank:false,
                name: 'staTime', 
                id: 'heraldstaTime',  
		anchor:'68%' ,                   //时间间隔   
                format:'G:i:s',                    //时间格式   
                invalidText:'时间格式无效',  
                fieldLabel:'开始时间'  
				},{ 
						xtype:'timefield',  
		columnWidth:.5 ,            
                maxValue:'23:30',                      //最大时间   
                maxText:'所选时间小于{0}',  
                minValue:'00:00',                      //最小时间   
                minText:'所选时间大于{0}',  
                maxHeight:70,  
                increment:30,   
				allowBlank:false,
                name: 'endTime', 
                id: 'heraldendTime',  
		anchor:'68%' ,                   //时间间隔   
                format:'G:i:s',                    //时间格式   
                invalidText:'时间格式无效',  
                fieldLabel:'结束时间'
},{//   格式
			                xtype:'textarea',
			                name: 'pattern',
			                id:'pattern',
			                fieldLabel:'督办内容格式',
			                width: 230,
							allowBlank:false,
			                anchor:'98%'
			              
		                },{// 操作类型
				           id:'buttonType',
			               xtype:'hidden',
			               name: 'type',
			               value: 'cancel'
			           }]
		        }]
		    });

		    // 发送请求-form初期化
			Anynote.ajaxRequest({
				baseParams: {handleId:<%=handleIds%>},
				action: '${pageContext.request.contextPath}/getHandle.action',
				callback: function(jsonResult){
		     	    editHandleFormPanel.getForm().setValues(jsonResult);
				}
			});

		    // 保存按钮
		    $("#editHandle-save-button").click(function(){
			    var form = editHandleFormPanel.getForm();
			    form.findField("targetName").setValue(checktext.toString()) ; 
			    if(form.isValid()){
			    	// 发送请求
					Anynote.ajaxRequest({
						baseParams: form.getValues(),
						action: '${pageContext.request.contextPath}/updateHandle.action?checkid='+checkid.toString(),
						callback: function(jsonResult){
						     handleListGrid.getStore().reload();
						     editHandleWindow.close();
						},
						showWaiting: true,
						failureMsg: '保存失败.'
					});
				}
			});
			
		 	// 取消按钮
		    $("#editHandle-cancel-button").click(function(){
		    	Ext.getCmp("buttonType").setValue("cancel");
		    	editHandleWindow.close();
			});
		});
	</script>
</head>
<body> 
<div id="editHandleDiv" style="width:100%;height:100%;">
	<div id="editHandleToolBarDiv"></div>
	<div id="editHandleFormDiv""></div>
</div>

<div id="textDiv" style="display:none">
<input type="text" name="comboxtreeHandle" id="comboxtreeHandle">
</div>
</body>
</html>